using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Core.Compare;
using Preparation;
using Tester.Forms;

namespace Tester.GuiActions.Actions.Impl
{
    public class CompareAction : BaseAction
    {
        public override bool Visible
        {
            get
            {
                return
                    (TesterMultyDocument.Instance != null &&
                     TesterMultyDocument.Instance.Suspended == TesterMultyDocument.SuspendStates.Stopped &&
                     TesterList.Instance != null &&
                     TesterList.Instance.SelectedItems.Count > 0 &&
                     TesterMainForm.Instance.TopControl == EmbededControlTags.TesterList);
                    
            }
        }

        public override void MainAction(object sender, EventArgs e)
        {
            if (Visible)
            {
                List<Test> testList = new List<Test>();
                foreach (ListViewItem it in TesterList.Instance.SelectedItems)
                {
                    if (it.Tag != null)
                    {
                        testList.Add((Test)it.Tag);
                    }
                }
                Core.Compare.DiffRTFPrinter rtfprint = new DiffRTFPrinter(testList);
                RtfStrings rtfLeftRight = rtfprint.RTFPrint();
                AnalizeDiffControl diffcontrol = new AnalizeDiffControl(rtfLeftRight._rtf_left, rtfLeftRight._rtf_right, rtfLeftRight._listLinksLeft, rtfLeftRight._listLinksRight);
                diffcontrol.Dock = DockStyle.Fill;
                TesterMainForm.Instance.PushControl(diffcontrol);
                //List<DiffShortInfo> diff = TesterMultyDocument.Instance.GetNewOldAndBothFiles(testList);

            }
        }
    }
}
